# Create a virtual environment with all tools installed
# ref: https://hub.docker.com/_/archlinux/
FROM archlinux:latest AS env

# Install system build dependencies
ENV PATH=/usr/local/bin:$PATH
RUN pacman -Syu --noconfirm git base-devel glibc cmake
RUN cmake -version
RUN pacman -Syu --noconfirm nodejs emscripten
ENV PATH=/usr/lib/emscripten:$PATH
RUN emcc -v

# Add the library src to our build env
FROM env AS devel
WORKDIR /home/project
COPY . .

FROM devel AS build
# To remove once https://gitlab.archlinux.org/archlinux/packaging/packages/emscripten/-/issues/7 is fixed
RUN ln -s em-config.py /usr/lib/emscripten/em-config
# To replace by emcmake once https://gitlab.archlinux.org/archlinux/packaging/packages/emscripten/-/issues/7 is fixed
RUN emcmake.py cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=make
RUN cmake --build build --target all -v
#RUN cmake --build build --target install -v

FROM build AS test
#RUN CTEST_OUTPUT_ON_FAILURE=1 cmake --build build --target test
RUN cd build && ctest -V
